﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Avaliacao
{
    class Tower : GameObject
    {
        protected int radius;       // Raio de alcance.
        protected int fireRate;     // Velocidade de tiro
        protected int cost;         // Custo
        protected bool isMenu;      // Se a torre faz parte do menu

        protected List<Animation> animations;
        protected int currentAnimation;
        public enum animIndexes { Still, Hover, Blocked };

        public int Radius
        {
            get { return this.radius; }
            set { this.radius = value; }
        }

        public int FireRate
        {
            get { return this.fireRate; }
            set { this.fireRate = value; }
        }

        public int Cost
        {
            get { return this.cost; }
            set { this.cost = value; }
        }


        public Tower(Texture2D texture, GameWindow Window, Vector2 pos, int radius, int fireRate, int cost, bool isMenu): base(texture, Window)
        {
            this.position = pos;
            this.radius = radius;
            this.fireRate = fireRate;
            this.cost = cost;
            this.isMenu = isMenu;

            Animation still = new Animation();
            still.width = 50;
            still.height = 50;
            still.frames = 1;
            still.frames_per_second = 1;
            still.Y = 0;
            still.name = "Still";

            Animation hover = new Animation();
            hover.width = 50;
            hover.height = 50;
            hover.frames = 3;
            hover.frames_per_second = 2;
            hover.Y = 1;
            hover.name = "Hover";

            Animation blocked = new Animation();
            blocked.width = 50;
            blocked.height = 50;
            blocked.frames = 1;
            blocked.frames_per_second = 1;
            blocked.Y = 2;
            blocked.name = "Blocked";

            this.animations = new List<Animation>();
            this.animations.Add(still);
            this.animations.Add(hover);
            this.animations.Add(blocked);
            this.currentAnimation = (int) Tower.animIndexes.Still;
        }
				
		public override void Update(GameTime gameTime)
		{
            // Método herdado de GameObject, temos método overloading (dois métodos com mesmo nome e parâmetros diferentes)
		}
				
		public void Update(GameTime gameTime, KeyboardState keyboard, KeyboardState last_keyboard, MouseState mouse, MouseState last_mouse)
		{
			
		}

        public Tower clone(Vector2 position)
        {
            return new Tower(this.texture, this.Window, position, this.radius, this.fireRate, this.cost, false);
        }

        public void setAnimation(int index)
        {
            this.currentAnimation = index;
        }

        public Animation getAnimation()
        {
            return animations.ElementAt(currentAnimation);
        }

        public int getAnimationIndex()
        {
            return currentAnimation;
        }
				
        public bool Collided(GameObject other)
        {
            if (this.collision.Intersects(other.Collision))
                return true;
            else
                return false;
        }
    }
}
